<?php

#$target_path = "./_workdir/ParaFuncsTest1.odt";

$target_path = "_workdir/content.xml";

$reader = new XMLReader();

#$reader->open("zip://" . $target_path . "#content.xml");
$reader->open($target_path);
$doc_data = array();

$parent = null;
      $pp = array();

while ($reader->read()) {
  if ($reader->nodeType == XMLREADER::ELEMENT) {
    $elm = $reader->name;
    switch($reader->name) {
    case 'style:style':
      // style def, usually in the beginning
      $n = $reader->getAttribute('style:name');
      $p = $reader->getAttribute('style:paragraph-properties');
      print $n . $p . "\n";
    case 'style:paragraph-properties':
      
      for ($i=1;$i<5;$i++) {
	$pp[$n]['level' . $i] = $reader->getAttribute("Level" . $i);
	$pp[$n]['view' . $i] = $reader->getAttribute("View" . $i);
      }
      break;
    case 'text:h':
      
      break;
    case 'text:p':
      // text paragraph
      $st = $reader->getAttribute("text:style-name");
      $sql = "INSERT INTO doc (level1,level2,level3,view1,view2,view3,text,style,level) VALUES (?,?,?,?,?,?,?,?,?)";
      printf("%s, %s, %s, %s, %s, %s, %s, %s, %s",
	     defined($pp[$st]['level1']) ? $pp[$st]['level1'] : '0',
	     defined($pp[$st]['level2']) ? $pp[$st]['level2'] : '0',
	     defined($pp[$st]['level3']) ? $pp[$st]['level3'] : '0',
	     defined($pp[$st]['view1']) ? $pp[$st]['view1'] : '0',
	     defined($pp[$st]['view2']) ? $pp[$st]['view2'] : '0',
	     defined($pp[$st]['view3']) ? $pp[$st]['view3'] : '0',
	     $reader->readString(),
	     $pp[$st][);
      
      break;
    default:
      //print "<other>" . $reader->readString() . "</other>\n";
    }
    
    $parent = $elm;
  }
}

print "<hr><pre>" . print_r($doc_data, true) . "</pre>";
print print_r($pp, true);
?>